package cn.seocoo.platform.report.service.impl;

import cn.seocoo.platform.common.constant.ClassContants;
import cn.seocoo.platform.common.core.text.Convert;
import cn.seocoo.platform.report.domain.Report;
import cn.seocoo.platform.report.mapper.ReportMapper;
import cn.seocoo.platform.report.service.IReportService;
import cn.seocoo.platform.user.domain.AppUser;
import cn.seocoo.platform.user.mapper.AppUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 举报 服务层实现
 *
 * @author wujian
 * @date 2019-12-23
 */
@Service
public class ReportServiceImpl implements IReportService {

    @Autowired
    private ReportMapper reportMapper;

    @Autowired
    private AppUserMapper appUserMapper;

    /**
     * 查询举报信息
     *
     * @param id 举报ID
     * @return 举报信息
     */
    @Override
    public Report selectReportById(Integer id) {
        return reportMapper.selectReportById(id);
    }

    /**
     * 查询举报列表
     *
     * @param report 举报信息
     * @return 举报集合
     */
    @Override
    public List<Report> selectReportList(Report report) {
        return reportMapper.selectReportList(report);
    }

    /**
     * 新增举报
     *
     * @param report 举报信息
     * @return 结果
     */
    @Override
    public int insertReport(Report report) {
        return reportMapper.insertReport(report);
    }

    /**
     * 修改举报
     *
     * @param report 举报信息
     * @return 结果
     */
    @Override
    public int updateReport(Report report) {
        return reportMapper.updateReport(report);
    }

    /**
     * 删除举报对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteReportByIds(String ids) {
        return reportMapper.deleteReportByIds(Convert.toStrArray(ids));
    }

    /**
     * @return int
     * @Author WuJian
     * @Description //举报
     * @Date 11:53 2019/12/23
     * @Param [report]
     **/
    @Override
    public int saveReport(Report report) {
        report.setDelFlag(ClassContants.NO_DEL_FLAG);
        Integer appUserId = report.getAppUserId();
        AppUser appUser = appUserMapper.selectAppUserById(appUserId);
        report.setCreateBy(appUser.getLoginName());
        return reportMapper.insertReport(report);
    }

}
